<?php

class Model_Prestagenerator {
	
	
	public function generatePrestaFile($titleProduct,$idCategory,$priceTaxInc,$taxRuleID,$reference,$supplierReference,$supplierID,$weight,$qty,$shortDes,$longDes,$imageUrls,$onlineOnly,$shop){
		
	/**
	 * The Following column is MUST
	 * Active 
	 * Name (Title)
	 * Category ID different of two website 
	 * Price include tax
	 * tax rule id is also different 
	 * reference 
	 * supplier reference 
	 * supplier ID?
	 * weight 
	 * qty 
	 * visibility both 
	 * shot description 
	 * long descritpion 
	 * test when in stock  in stock 
	 * text when back order allowed Back Order Available 
	 * Available for order 1
	 * image urls with | 
	 * available online ONLY -> very useful if force 0 by default 
	 * considerion new 
	 */	
		
	$active = 1;
	$visibility = 'both';
	$txtWhenInStock = 'In Stock';
	$txtWhenBackOrder = 'Back Order Available';
	$availableForOrder = 1;
	$condition = 'new';
		
	$fileName = "presta_import_".Model_DatetimeHelper::dateToday().".csv";

	$importFileName = $shop."_".$fileName;
	// check if file exist 
	if(!file_exists(getcwd().PRESTA_FOLDER.'/'.$importFileName)){
		//create file and put the file header there 
		$arrHead = array(
			'Active (0/1)',
			'Name *',
			'Categories (x,y,z...)',
			'Price tax excluded or Price tax included',
			'Tax rules ID',
			'Reference #',
			'Supplier reference #',
			'Supplier',
			'Weight',
			'Quantity',
			'Visibility',
			'Short description',
			'Description',
			'Text when in stock',
			'Text when backorder allowed',
			'Available for order (0 = No, 1 = Yes)',
			'Image URLs (x,y,z...)',
			'Available online only (0 = No, 1 = Yes)',
			'Condition');
		
		$fl = fopen(getcwd().PRESTA_FOLDER.'/'.$importFileName,'w');
		fputcsv($fl, $arrHead);
		fclose($fl);
	}
		
	$fl = fopen(getcwd().PRESTA_FOLDER.'/'.$importFileName,'a');
	$arrContent = array(
			$active,
			$titleProduct,
			$idCategory,
			$priceTaxInc,
			$taxRuleID,
			$reference,
			$supplierReference,
			$supplierID,
			$weight,
			$qty,
			$visibility,
			$shortDes,
			$longDes,
			$txtWhenInStock,
			$txtWhenBackOrder,
			$availableForOrder,
			$imageUrls,
			$onlineOnly,
			$condition
			);
		
	fputcsv($fl, $arrContent);
	fclose($fl);	
	}

}

?>